package com.ruoyi.web.controller.production.pesticide;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.pesticide.PesticideName;
import com.ruoyi.production.service.pesticide.IPesticideNameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药名称Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/pesticideName")
public class PesticideNameController extends BaseController
{
    @Autowired
    private IPesticideNameService pesticideNameService;

    /**
     * 查询农药名称列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:list')")
    @GetMapping("/list")
    public TableDataInfo list(PesticideName pesticideName)
    {
        startPage();
        List<PesticideName> list = pesticideNameService.selectPesticideNameList(pesticideName);
        return getDataTable(list);
    }

    /**
     * 导出农药名称列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:export')")
    @Log(title = "农药名称", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PesticideName pesticideName)
    {
        List<PesticideName> list = pesticideNameService.selectPesticideNameList(pesticideName);
        ExcelUtil<PesticideName> util = new ExcelUtil<PesticideName>(PesticideName.class);
        return util.exportExcel(list, "农药名称数据");
    }

    /**
     * 获取农药名称详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:query')")
    @GetMapping(value = "/{pesticideNameId}")
    public AjaxResult getInfo(@PathVariable("pesticideNameId") Long pesticideNameId)
    {
        return AjaxResult.success(pesticideNameService.selectPesticideNameById(pesticideNameId));
    }

    /**
     * 新增农药名称
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:add')")
    @Log(title = "农药名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PesticideName pesticideName)
    {
        return toAjax(pesticideNameService.insertPesticideName(pesticideName));
    }

    /**
     * 修改农药名称
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:edit')")
    @Log(title = "农药名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PesticideName pesticideName)
    {
        return toAjax(pesticideNameService.updatePesticideName(pesticideName));
    }

    /**
     * 删除农药名称
     */
    @PreAuthorize("@ss.hasPermi('production:pesticideName:remove')")
    @Log(title = "农药名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticideNameIds}")
    public AjaxResult remove(@PathVariable Long[] pesticideNameIds)
    {
        return toAjax(pesticideNameService.deletePesticideNameByIds(pesticideNameIds));
    }
}
